﻿// --------------------------------
// <copyright file="CalculationParameter.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;

namespace Tronsoft.Actucal.CalculationEngineCreator
{
    /// <summary>
    /// This class represents a parameter for the calculation model.
    /// </summary>
    /// <typeparam name="T">The type of the parameter.</typeparam>
    public class CalculationParameter<T> : ICalculationParameter 
    {
        private readonly string name;
        private T value;

        /// <summary>
        /// The default constructor.
        /// </summary>
        public CalculationParameter() : this(string.Empty, default(T))
        {
        }

        /// <summary>
        /// A constructor.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        public CalculationParameter(string name) : this(name, default(T))
        {
        }

        /// <summary>
        /// A constructor.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="value">The value of the parameter.</param>
        public CalculationParameter(string name, T value)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            if (name.Contains(" "))
                throw new ArgumentException("A name cannot contains spaces.", "name");

            this.name = name;
            Value = value;
        }

        /// <summary>
        /// The value of the parameter.
        /// </summary>
        public T Value
        {
            get { return value; }
            set { this.value = value; }
        }

        /// <summary>
        /// The name of the parameter.
        /// </summary>
        public string Name
        {
            get { return name; }
        }

        /// <summary>
        /// The type of the parameter.
        /// </summary>
        public Type Type
        {
            get { return typeof(T); }
        }

        #region ICalculationParameter Members

        /// <summary>
        /// The value of the parameter.
        /// </summary>
        object ICalculationParameter.Value
        {
            get
            {
                return value;
            }
            set
            {
                this.value = (T)value;
            }
        }

        string ICalculationParameter.Name
        {
            get { return name; }
        }

        #endregion
    }
}